package com.example.hystrixdemo.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

/**
 * @Package: com.example.hystrixdemo.service
 * @ClassName: UserService
 * @Author: Think
 * @CreateTime: 2021/7/8 13:52
 * @Description:
 */
@Service
public class UserService {

    @HystrixCommand(fallbackMethod = "handleNullUserName")
    public String getUserAddress(String userName) throws Exception {
        if(ObjectUtils.isEmpty(userName) || !"Hystrix".equals(userName)){
            throw new Exception("userName is null");
        }
        return "Hystrix";
    }

    public String  handleNullUserName(String userName){
        return "您输入的userName为空：" + userName;
    }

}
